/*
 * @Author: ZhanXie
 * @Date: 2019-12-02 16:23:08
 * @LastEditors  : ZhanXie
 * @LastEditTime : 2019-12-28 11:01:17
 * @Description: 写日志
 * @FilePath: /node-demo/blog-origin/src/util/log.js
 */
const fs = require('fs')
const path = require('path')

// 生成 write stream
function createWriteStream(filename) {
  const fullFileName = path.join(__dirname, '../', '../', 'logs', filename)
  const writeStream = fs.createWriteStream(fullFileName, {
    flags: 'a' // append 追加内容
  })
  return writeStream
}

// 写日志
function writeLog(writeStream, log) {
  writeStream.write(log + '\n') // 关键代码
}

// 写访问日志
const accesswriteStream = createWriteStream('access.log')

function access(log) {
  writeLog(accesswriteStream, log)
}

module.exports = {
  access
}